package com.ktjy.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ktjy.pojo.Storage;
import com.ktjy.service.IStorageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jjx
 * @since 2025-01-16
 */
@Controller
@RequestMapping("/storage")
public class StorageController {
    Logger logger = LoggerFactory.getLogger(StorageController.class);
    @Autowired
    IStorageService iStorageService;

    @RequestMapping("/list")
    public String list(Storage storage,
                       @RequestParam(value = "pageIndex", defaultValue = "1") Integer pageIndex,
                       @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                       Model model) {
        try {
            IPage<Storage> pager=iStorageService.findPage(storage, pageIndex,pageSize);
            model.addAttribute("pager", pager);

            //回显数据
            model.addAttribute("condition", storage);
        } catch (Exception e) {
            logger.error("StorageController 中的 list 方法执行发生错误。 ", e);
            throw new RuntimeException(e);
        }
        return "storage/list";
    }
}
